From 63852bee4735407c260a034cac29ee1a8f100300 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Tue, 15 Nov 2005 19:19:02 +0100 Subject: [PATCH] Make watchStart and watchMain global functions rather than classmethods, meaning that we no longer need to prefix all the field accesses with cls. Signed-off-by: Ewan Mellor --- tools/python/xen/xend/xenstore/xswatch.py | 70 +++++++++++------------ 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/tools/python/xen/xend/xenstore/xswatch.py b/tools/python/xen/xend/xenstore/xswatch.py index b087aeacc5..fbf165c019 100644 --- a/tools/python/xen/xend/xenstore/xswatch.py +++ b/tools/python/xen/xend/xenstore/xswatch.py @@ -13,47 +13,45 @@ from xen.xend.XendLogging import log class xswatch: - watchThread = None - xs = None - xslock = threading.Lock() - def __init__(self, path, fn, *args, **kwargs): self.path = path self.fn = fn self.args = args self.kwargs = kwargs - xswatch.watchStart() - xswatch.xs.watch(path, self) + watchStart() + xs.watch(path, self) + +watchThread = None +xs = None +xslock = threading.Lock() - def watchStart(cls): - cls.xslock.acquire() +def watchStart(): + global watchThread + global xs + + xslock.acquire() + try: + if watchThread: + return + xs = xshandle() + watchThread = threading.Thread(name="Watcher", target=watchMain) + watchThread.setDaemon(True) + watchThread.start() + finally: + xslock.release() + + +def watchMain(): + while True: try: - if cls.watchThread: - return - cls.xs = xshandle() - cls.watchThread = threading.Thread(name="Watcher", - target=cls.watchMain) - cls.watchThread.setDaemon(True) - cls.watchThread.start() - finally: - cls.xslock.release() - - watchStart = classmethod(watchStart) - - - def watchMain(cls): - while True: - try: - we = cls.xs.read_watch() - watch = we[1] - res = watch.fn(*watch.args, **watch.kwargs) - if not res: - cls.xs.unwatch(watch.path, watch) - except: - log.exception("read_watch failed") - # Ignore this exception -- there's no point throwing it - # further on because that will just kill the watcher thread, - # which achieves nothing. - - watchMain = classmethod(watchMain) + we = xs.read_watch() + watch = we[1] + res = watch.fn(*watch.args, **watch.kwargs) + if not res: + xs.unwatch(watch.path, watch) + except: + log.exception("read_watch failed") + # Ignore this exception -- there's no point throwing it + # further on because that will just kill the watcher thread, + # which achieves nothing. -- 2.30.2